package com.tyt.lelan;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

public class WebAcitivty extends Activity {

	private WebView wv;
	private Bundle mData;
	private String description;
	private String title;
	private String link;

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.a_web);		
		getData();
		initialView();
		handler.post(loadPage);
	}
	
	private void initialView(){
		if(title!=null)
			((TextView) findViewById(R.id.tv_title)).setText(title);
		wv = (WebView) findViewById(R.id.webview);
		wv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
		WebSettings webSettings = wv.getSettings();
		webSettings.setSaveFormData(true);
		webSettings.setJavaScriptEnabled(false);
		webSettings.setSupportZoom(true);
		wv.setDrawingCacheEnabled(true);	
		wv.setWebViewClient(new WebViewClient(){
			@Override
			public boolean shouldOverrideUrlLoading(WebView  view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		wv.setWebChromeClient(new WebChromeClient(){
			//设置网页加载的进度条  
          public void onProgressChanged(WebView view,int newProgress){  
          	WebAcitivty.this.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress*100);  
              super.onProgressChanged(view, newProgress);  
          }  

		});
	}
	
	private void getData(){
		mData=getIntent().getExtras();
		if(mData!=null){	
			link = mData.getString("link");
			title = mData.getString("title");
			description = mData.getString("description");
		}
	}
	
	private Runnable loadPage =new Runnable(){

		@Override
		public void run() {
			// TODO Auto-generated method stub
			wv.loadUrl(link);
		}
		
	};
	
	
	public  void updateWebView(String title,String link,String brief){
		
	}
	

	private Handler handler = new Handler() 
	{

		/* (non-Javadoc)
		 * @see android.os.Handler#handleMessage(android.os.Message)
		 */
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch(msg.what){
			case 0:
				
				break;
			}
		}
    	
	};

}
